package in.co.codedoc.json;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class JSONParserTests
{
	@Test
	public void testDecode()
	{		
		String justLong = "4132987654";
		
		JSONValue longValue = JSONValue.Decode(justLong);
		
		assertTrue("Wong type returned.", longValue instanceof JSONLongValue);

		String justString = "'41\"3298\\'7654'";
		
		JSONValue stringValue = JSONValue.Decode(justString);
		
		assertTrue("Wong type returned.", stringValue instanceof JSONStringValue);
		
		System.out.println("Read:" + ((JSONStringValue)stringValue).GetValue());

		String objectString = "{a:b,c:d,e:213}";
		
		JSONValue objectValue = JSONValue.Decode(objectString);
		
		assertTrue("Wong type returned.", objectValue instanceof JSONObjectValue);
		
		System.out.println(objectValue.Encode());
	}

	@Test
	public void testEncode()
	{
		JSONStringValue jsonString = new JSONStringValue("c:\\temp");
		
		System.err.println("Encoded:" + jsonString.Encode());
		
		System.out.println("c:\\temp -> Encode-As-String -> Decode:" + ((JSONStringValue)JSONValue.Decode(jsonString.Encode())).GetValue());
	}

}
